package com.xy.repository;

import com.xy.entity.User;
import com.xy.entity.msg.SystemMsg;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by Thinkpad on 2018/1/4.
 */
public interface UserRepository extends JpaRepository<User, String> {

    User findByUsername(String username);

    User findByUsernameAndPassword(String account, String password);

    //修改头像
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE `user` SET head=?1 where uuid=?2", nativeQuery = true)
    int updateHead(@Param("url") String url, @Param("uuid") String uuid);

    //修改昵称
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE `user` SET nickname=?1 where uuid=?2", nativeQuery = true)
    int updateNickname(@Param("nickname") String nickname, @Param("uuid") String uuid);


    //修改手机号
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE `user` SET phone=?1 where uuid=?2", nativeQuery = true)
    int updatePhone(@Param("phone") String phone, @Param("uuid") String uuid);

    //修改性别
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE `user` SET gender=?1 where uuid=?2", nativeQuery = true)
    int updateGender(@Param("gender") String gender, @Param("uuid") String uuid);

    //修改出生年月
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE `user` SET birth=?1 where uuid=?2", nativeQuery = true)
    int updateBirth(@Param("birth") java.sql.Date birth, @Param("uuid") String uuid);

    //查询
    User findAllByUuid(String userId);

}
